<?php
/***
 * 描述：系统基类模块
 * @category		
 * @package		Lib			
 * @subpackage	Action.System	
 * @author		wanght <whtaok@gmail.com>
 * @since		2013-4-6
 * @version		$Id: SystemAction.class.php 3 2013-10-14 02:49:41Z whtaok@gmail.com $
 */
class SystemAction extends AppAction {
	/**
	 *
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected  function _initialize() {
		
	}

	/**
	 * 初始化树状菜单
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected function initMenuTree($menu_type) {
		//1.根据菜单类型取得菜单列表
		$model	=	D('sys/AccessMenuView');
		$menu	=	$model->getMenuForUsing($menu_type);
		
		//2.生成菜单树型数组(common.php->list_to_tree)
		$menu_tree = list_to_tree($menu,'menu_id','menu_pid','children',0);
		//3.文件缓存数组
		F('menu_tree'.$menu_type,$menu_tree);
		//4.返回树状数组
		return $menu_tree;
	}

	/**
	 * 提取头部菜单数组
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected function getMenuTop($menu_type){
		//提取树型菜单数组
		$menu_tree = F('menu_tree'.$menu_type);
		if(!$menu_tree){
			$menu_tree = $this->initMenuTree($menu_type);
		}
		
		//提取头部菜单数组
		$menu_top = array();
		foreach ($menu_tree as $item) {
			$menu_top[] = array('menu_id'=>$item['menu_id'],'menu_title'=>$item['menu_title']);
		}
		return $menu_top;
	}

	/**
	 * 提取子菜单数组
	 * @access		protected
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	protected function getMenuSub($menu_type,$menu_id){
		//提取树型菜单数组
		$menu_tree = F('menu_tree'.$menu_type);
		if(!$menu_tree){
			$menu_tree = $this->initMenuTree($menu_type);
		}

		//提取子菜单数组
		$menu_sub = $menu_tree[$menu_id]['children'];
		foreach ($menu_sub as $key=>$value){
			if(isset($value['children'])){
				foreach($value['children'] as $c_key=>$c_value){
					if ($c_value['action_params']){
						$action_params = explode('&', $c_value['action_params']);
						foreach ($action_params as $name_value) {
							$data_arg = explode('=', $name_value);
							$data_args[$data_arg[0]] = $data_arg[1];
						}
					}
					$menu_sub[$key]['children'][$c_key]['url']=U($c_value['group_name'].'/'.$c_value['module_name'].'/'.$c_value['action_name'], $data_args);
				}
			}
		}
		F('menu_tree_sub',$menu_sub);
		return $menu_sub;
	}
	
	protected function initNodeList(){
		$model	=	D('sys/SysAdminNode');
		$node_list = $model->where('is_valid=2')->order('group_name,module_name,action_name,ordlist')->select();
		return $node_list;
	}
	
}

?>